package cs3343.project.family;

import javax.swing.JOptionPane;

public class ToolCardFrame {
	
	public ToolCardFrame(Character character, Card card, String cardType){
		JOptionPane.showMessageDialog(null, "You get a " + card.description, cardType, 1);
		character.addCard(card);
		for(int i = 0; i < character.cardsOwned.size(); i++){
		System.out.println(character.cardsOwned.get(i).description);
		}
		System.out.println("==============^"+ character.name+ "^==============");
	}
	
	public static boolean searchType(Card card, String cardType){
		int toIndex = card.description.indexOf("]");

		String toChinese = "";
		
		switch(cardType){
		case "OralCard": toChinese = "說話";break;
		case "ActionCard": toChinese = "動作";break;
		case "EventCard": toChinese = "事件";break;
		}
		
		if(card.description.lastIndexOf(toChinese, toIndex) != -1)
			return true;		
		return false;
	}
	
	public static String[] availableCards(Character character, String cardType){
		int AvailableCardNum = 0;
		
		//get the combobox size
		for(int i = 0; i < character.cardsOwned.size(); i++)
			if(ToolCardFrame.searchType(character.cardsOwned.get(i), cardType))
				AvailableCardNum++;
		
		String[] option = new String[AvailableCardNum+1];
		option[0] = "None";
		
		//add item to combobox
		for(int i = 0, j = 1; i < character.cardsOwned.size(); i++)
			if(ToolCardFrame.searchType(character.cardsOwned.get(i), cardType)){
				option[j] = character.cardsOwned.get(i).description;
				j++;
			}
		
		return option;
	} 
}